package com.jkm.service.impl;

import com.jkm.mapper.write.WriteUserMapper;
import com.jkm.model.User;
import com.jkm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by 四声草 on 2018/4/10.
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private WriteUserMapper writeUserMapper;

    @Override
    @Transactional
    public int save(User user) {
        int a = writeUserMapper.save(user);
        if(a == 0) {
            throw new RuntimeException("can not insert user");
        }
//        System.out.println(1/0);
        return a;
    }

    @Override
    public User selectById(Integer id) {
        System.out.println("调用service实现方法连接数据库");
        return writeUserMapper.selectById(id);
    }

    @Override
    public List<User> selectAll() {
        return writeUserMapper.selectAll();
    }
}
